﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MaxStudio.Concrete.DBUtility;
using MaxStudio.Concrete.Server.Dao;
using MaxStudio.Concrete.Server.Interface;

namespace MaxStudio.Concrete.Server.Service
{
    public class NeedPayDetailsService : ServiceHandle, INeedPayDetails
    {
        #region INeedPayDetails Members

        public OperationResult<List<tb_NeedPayDetail>> GetAllNeedPayDetails()
        {
            OperationResult<List<tb_NeedPayDetail>> result = new OperationResult<List<tb_NeedPayDetail>>();
            ConcreteDaoDataContext dataContext = getDateContext();
            List<tb_NeedPayDetail> list = new List<tb_NeedPayDetail>();
            try
            {
                list = dataContext.GetAllNeedPayDetail();
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_NeedPayDetail> GetNeedPayDetailsById(int id)
        {
            OperationResult<tb_NeedPayDetail> result = new OperationResult<tb_NeedPayDetail>();
            ConcreteDaoDataContext dataContext = getDateContext();
            tb_NeedPayDetail NeedPay;
            try
            {
                NeedPay = dataContext.GetNeedPayDetailById(id);
                if (NeedPay == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = NeedPay;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_NeedPayDetail>> GetNeedPayDetailsByNeedPayId(int NeedPayId)
        {
            OperationResult<List<tb_NeedPayDetail>> result = new OperationResult<List<tb_NeedPayDetail>>();
            ConcreteDaoDataContext dataContext = getDateContext();
            List<tb_NeedPayDetail> list = new List<tb_NeedPayDetail>();
            try
            {
                list = dataContext.GetNeedPayDetailsByNeedPayId(NeedPayId);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_NeedPayDetail> CreateNeedPayDetails(tb_NeedPayDetail entity)
        {
            OperationResult<tb_NeedPayDetail> result = new OperationResult<tb_NeedPayDetail>();
            ConcreteDaoDataContext dataContext = getDateContext();

            try
            {
                dataContext.CreateNeedPayDetail(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_NeedPayDetail> ModifyNeedPayDetails(tb_NeedPayDetail entity)
        {
            OperationResult<tb_NeedPayDetail> result = new OperationResult<tb_NeedPayDetail>();
            ConcreteDaoDataContext dataContext = getDateContext();

            try
            {
                dataContext.ModifyNeedPayDetail(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_NeedPayDetail> DeleteNeedPayDetails(tb_NeedPayDetail entity)
        {
            OperationResult<tb_NeedPayDetail> result = new OperationResult<tb_NeedPayDetail>();
            ConcreteDaoDataContext dataContext = getDateContext();

            try
            {
                dataContext.DeleteNeedPayDetail(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        #endregion
    }
}
